package b1.scenes.suspect
{
	import b1.conifg.*;
	import b1.controls.basic.BasicMessage;
	import b1.net.*;
	import b1.players.*;
	
	import com.greensock.*;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.*;

	public class ClueItem extends Sprite
	{
		private var clue:ClueInfo;
		private var clueTip:BasicMessage;
		private var clueConfig:ClueConfig;
		
		public function ClueItem(clue:ClueInfo)
		{
			super();
			this.clue = clue;
			clueConfig = Config.clueConfigs[clue.clueIndex];

			//证物袋图片
			var ClueBagImg:Class = ResourceHelper.getInstance().getClassByName("ClueMcBackground");
			var clueBagImg:Sprite = new ClueBagImg();
			clueBagImg.width = 60;
			clueBagImg.scaleY = clueBagImg.scaleX;
			clueBagImg.rotation = -10;
			addChild(clueBagImg);
			
			
			//线索图片
			var imgStr:String;
			if (clue.clueIndex == 1)
			{
				imgStr = "Clue" + clue.clueIndex.toString() + "_" + 0;
			}
			else if(clue.clueIndex == 0)
			{
				imgStr = "Clue" + clue.clueIndex.toString() + "_0_" + clue.jawType.toString();
			}
			else
			{
				imgStr = "Clue" + clue.clueIndex.toString() + "_" + clue.clueValue.toString();
			}
			var ClueImage:Class = ResourceHelper.getInstance().getClassByName(imgStr);
			var clueImg:Sprite = new ClueImage();
//			clueImg.width = 55;
//			clueImg.scaleY = clueImg.scaleX;
			var clueImgDiag:Number = Math.sqrt(clueImg.width * clueImg.width + clueImg.height * clueImg.height);
			var ratio:Number = 80 / clueImgDiag;
			clueImg.scaleX = ratio;
			clueImg.scaleY = ratio;
			clueImg.x = 10;
			clueImg.y = 13;
			addChild(clueImg);
			
			//标签图片
			var ClueLabelImg:Class = ResourceHelper.getInstance().getClassByName("ClueLabelImg");
			var clueLabelImg:Sprite = new ClueLabelImg();
			clueLabelImg.width = 120;
			clueLabelImg.scaleY = clueLabelImg.scaleX;
			clueLabelImg.rotation = -5;
			clueLabelImg.x = 40;
			addChild(clueLabelImg);
			
			//类型名称
			var titleText:TextField = new TextField();
			titleText.selectable = false;
        	titleText.autoSize = TextFieldAutoSize.LEFT;
			titleText.defaultTextFormat = new TextFormat("微软雅黑", 15, 0x000000);
			titleText.x = 90;
			titleText.width = 50;
			titleText.wordWrap = true;
			titleText.y = (clueLabelImg.height - titleText.height) / 2 - 40;
			if (clue.clueIndex != 3)
			{
				titleText.y = 12;
			}
			titleText.text = clueConfig.name + ": ";
			titleText.scaleX = titleText.width / (titleText.width + 1);
			titleText.scaleY = titleText.height / (titleText.height + 1);
			titleText.z = 0;
			titleText.rotationZ = 25;
			addChild(titleText);
			//线索取值
			var valueText:TextField = new TextField();
			valueText.selectable = false;
        	valueText.autoSize = TextFieldAutoSize.LEFT;
			valueText.defaultTextFormat = new TextFormat("微软雅黑", 20, 0x000000,true);
			valueText.scaleX = valueText.width/(valueText.width+1);
			valueText.scaleY = valueText.height/(valueText.height+1);
			valueText.z = 0;
			valueText.rotationZ = 25;
			valueText.text = clueConfig.values[clue.clueValue];
			if (clue.clueIndex == 3)
			{
				valueText.x = 117;
				valueText.y = 27;
			}
			else
			{
				valueText.x = 125;
				valueText.y = 28;
			}
			addChild(valueText);
			
			this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
		}
		
		private function onMouseOver(event:MouseEvent):void
		{
			if (null == clueTip)
			{
				var textStr:String = "罪犯遗落的" + clueConfig.name + "线索";
				clueTip = new BasicMessage(90, 50, textStr, 0x50AF50, 0x000000, true);
				clueTip.y = - clueTip.height;
				addChild(clueTip);
			}
		}
		
		private function onMouseOut(event:MouseEvent):void
		{
			if(null != clueTip && null != clueTip.parent)
			{
				clueTip.parent.removeChild(clueTip);
				clueTip = null;
			}
		}
		
	}
}